package com.hp.attendance.serlvet.position;

import com.hp.attendance.entity.Position;
import com.hp.attendance.service.PositionService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
@WebServlet("/PositionAdd")
public class PositionAddServlet extends HttpServlet {
    private PositionService positionService = new PositionService();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        try {
            String positionNumber = req.getParameter("positionNumber");
            String name = req.getParameter("name");
            String level = req.getParameter("level");
            String notes = req.getParameter("notes");
            Position position = new Position(Integer.parseInt(positionNumber),name,level,notes);
            positionService.PositionAdd(position);
            req.getRequestDispatcher("/positionList").forward(req,resp);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
